<template>
  <div class="container">
    <div class="top">
      <div class="left">
        <span>关键字</span>
        <el-input v-model="input" style="width: 300px"></el-input>
      </div>
      <div class="right">
        <el-button class="clear" @click="clear">清除</el-button>
        <el-button type="primary" @click="search">搜索</el-button>
      </div>
    </div>
    <div class="data">
      <i class="el-icon-info"></i>
      <span>数据一共{{ 10 }}条</span>
    </div>
    <div class="main">
      <el-table
        :data="list"
        style="width: 100%"
        :header-cell-style="{ background: '#f5f7fa' }"
      >
        <el-table-column prop="id" label="编号" width="200"> </el-table-column>
        <el-table-column prop="questionType" label="题型" width="100">
          <template slot-scope="{ row }">
            <span v-if="row.questionType == 1">单选</span>
            <span v-else-if="row.questionType == 2">多选</span>
            <span v-else>简答</span>
          </template>
        </el-table-column>
        <el-table-column label="题目编号" width="200">
          <template slot-scope="{ row }">
            <div
              v-for="(item, index) in row.questionIDs"
              :key="index"
              class="questionIDs"
            >
              {{ item.number }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="addTime" label="录入时间"> </el-table-column>
        <el-table-column prop="totalSeconds" label="答题时间(s)">
        </el-table-column>
        <el-table-column prop="accuracyRate" label="正确率(%)">
        </el-table-column>
        <el-table-column prop="userName" label="录入人"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="{ row }">
            <a
              href="javascript:;"
              class="el-icon-delete delet"
              @click="delRandom(row)"
            ></a>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-row type="flex" justify="end" style="height: 50px" align="middle">
      <el-pagination
        :page-sizes="[20, 30, 40, 50]"
        :page-size="10"
        :total="page.total"
        background
        @current-change="changePage"
        @size-change="changePageSize"
        layout="prev, pager, next, sizes, jumper"
      >
      </el-pagination>
    </el-row>
  </div>
</template>

<script>
import { randoms, removeRandoms } from "../../api/hmmm/questions";
export default {
  data() {
    return {
      input: "",
      page: {
        page: 1,
        pagesize: 20,
        total: 0,
        pages: 20,
        keyword: "",
        
      },
      list: [],
    };
  },
  methods: {
    clear() {
      this.input = "";
    },
    async getRandomList() {
      const result = await randoms(this.page);
      this.list = result.data.items;
      console.log(result.data);
      this.page.total = result.data.counts;
      console.log(this.list);
    },
    search() {
      console.log(this.input);
      this.page.keyword = this.input;
      console.log(this.page.keyword);
      this.getRandomList();
    },
    async delRandom(data) {
      await removeRandoms(data);
      this.getRandomList();
    },
    changePage(newPage) {
      this.page.page = newPage;
      this.getRandomList();
    },
    changePageSize(newpage) {
      this.page.pagesize = newpage;
      this.getRandomList();
    },
  },
  created() {
    this.getRandomList();
  },
};
</script>

<style scoped >
.container {
  margin: 10px;
  background-color: #fff;
}
.top {
  display: flex;
  justify-content: space-between;
}
.top .left {
  padding: 20px 40px;
}
.top .left span {
  margin-right: 10px;
}
.top .right {
  margin-right: 10px;
  padding-top: 20px;
}
.data {
  color: #777;
  font-size: 13px;
  margin: 0 25px;
  background-color: #f4f4f5;
  padding: 10px 18px;
  border-radius: 10px;
}
.main {
  margin-top: 20px;
  padding: 0 25px;
}
.main .delet {
  width: 30px;
  height: 30px;
  border-radius: 15px;
  text-align: center;
  line-height: 30px;
  border: 1px solid #fcd5d5;
  color: #f78181;
  background-color: #fef0f0;
}
.main .questionIDs {
  color: #0090ff;
}
</style>
